<template>
    <div
        id="usermgr"
        v-loading="loading"
    >
        <v-tableTitle
            :btnConfig="btnConfig"
            :tableSelectData="tableSelectData"
            :title="$t('security.menuSetting')"
            @del="del"
            @newCreate="newCreate"
        ></v-tableTitle>
        <v-table
            :pageSize="pageSize"
            :page="page"
            :tableConfig="tableConfig"
            :tableData="tableData"
            :total="total"
            @findData="getTableData"
            @getTableData="getTableData"
            @searhData="searhData"
            @selectData="selectData"
            @setdialog="setdialog"
            @upData="getTableData"
            ref="table"
        ></v-table>
    </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";

export default {
    name: "umenuRun",
    mixins: [baseMixin, config],
    data() {
        return {
            loading: false,
            tableConfig: [
                {
                    label: this.$t("security.menuId"),
                    prop: "selfid",
                    input: "input",
                },
                {
                    label: this.$t("security.urlLocation"),
                    prop: "url",
                    input: "input",
                },
                {
                    label: this.$t("security.menuLevel"),
                    prop: "wmwhse",
                    input: "input",
                },

                {
                    label: this.$t("security.menuName"),
                    prop: "description",
                    input: "input",
                },
                {
                    type: "input",
                    label: this.$t("security.icon"),
                    props: "icon",
                },
                {
                    label: this.$t("security.menuParentId"),
                    prop: "parentid",
                    input: "input",
                },
                {
                    label: this.$t("security.isRfMenu"),
                    prop: "isrf",
                    input: "select",
                    options: this.getOptions("codelkup/INTLEAVTSK")
                },
            ],
            tableData: [],
            pageSize: 10,
          page: 1,
            total: 0,
            tableSelectData: [],
            tableSearhData: {},
        };
    },
    computed: {
        btnConfig() {
            return [
                {label: this.$t('common.create'), certigier: this.newStatus||!this.btnPermNameList.includes('EN010301'), invalid: "newCreate"},
                {label: this.$t('common.delete'), certigier: this.deleteStatus||!this.btnPermNameList.includes('EN010302'), disabled: true, invalid: "del"},
            ]
        }
    },
    created() {
    },
    methods: {
        newCreate() {
            this.$store.commit("setNewFlag", true);
            this.$router.push({name: 'umenuRunDeawer'});
        },
        selectData(data) {
            this.tableSelectData = data;
        },
        //删除
        del(data) {
            this.$api.post(`/deleteUmenu`, data).then(res => {
                
                    this.$message.success(res.returnMgr);
                    this.getTableData(1, {});
                
            }).finally(() => {
                
            })
        },
        async getTableData(page, data) {
            try {
                this.loading = true;
                let res = await this.$api.post(`/queryUmenu/${page}`, data);
                
                    this.tableData = res.page.list;
                  this.page = res.page.curpage;
                    this.pageSize = res.page.pageSize;
                    this.total = res.page.total;
                
            } catch (e) {
                this.$message.error(e);
            } finally {
                this.loading = false;
            }
        },
        //搜索的值
        searhData(data, up) {
            if (!up) {
                this.tableSearhData = data;
            } else {
                this.tableSearhData = data;
                this.getTableData(1, this.tableSearhData);
            }
        },
        //设置弹框
        setdialog(data) {
            this.$store.commit("setRouteData", data);
            this.$router.push({name: 'umenuRunDeawer'});
        },
    },
    mounted() {
        this.$store.commit("setSkip", {});
        this.$store.commit("setNewFlag", false);
        this.$store.commit("setTemporary", "");
        this.$store.commit("setRouteData", {});
        this.getTableData(1, {});
    },
    watch: {
        tableSelectData(data) {
            if (data.length > 0) {
                this.deleteStatus = false;
            } else {
                this.deleteStatus = true;
            }
        }
    },
    components: {
        "v-tableTitle": tableTitle,
        "v-table": table,
    }
};
</script>

<style scoped>
#usermgr {
    width: 100%;
    height: 99%;
    padding-top: 6px;
}
</style>
